#include "Blocks/WaterPlantBlock.h"
#include "Subsystems/SubsystemTerrain.h"
#include "GameSingleton.h"
#include "Managers/BlocksManager.h"

namespace PocketSurvival
{
    WaterPlantBlock::WaterPlantBlock()
    {
        addInheritance(this);
    }

    BlockPlacementData WaterPlantBlock::getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult)
    {
        Point3 point = raycastResult.cellFace.point + CellFace::FaceToPoint3(raycastResult.cellFace.face);
        int32_t cellValue = GameSingleton::singletonPtr->getSingleton<SubsystemTerrain>()->getCellValue(point);
        int32_t num  = Terrain::ExtractContents(cellValue);
        int32_t data = Terrain::ExtractData(cellValue);
        BlockPlacementData result;
        if (GameSingleton::blocksManager->blocks[num]->isBlock<WaterBlock*>())
        {
        	result.cellFace = raycastResult.cellFace;
        	result.value = Terrain::MakeBlockValue(getIndex(), 0, data);
        	return result;
        }
        return result;
    }

} // namespace PocketSurvival
